Page({
  data: {
    theme: 'light',
    result: '',
    schema:[
      {
        label:'扫码类型',
        prop:'scanType',
        type:'multiSelector',
        labelOptions:['一维码','二维码','小程序码','Data Matrix 码','PDF417 条码'],
        valueOptions:['barCode','qrCode','wxCode','datamatrix','pdf417'],
      }
    ],
    formData:{
      scanType:['barCode', 'qrCode', 'wxCode']
    },
    title:'扫码',
    res:''
  },

  getFormData(e) {
    this.setData({
      formData:e.detail.formData
    })
  },

  scanCode() {
    const that = this
    wx.scanCode({
      scanType: this.data.formData.scanType,
      success(res) {
        that.setData({
          result: res.result,
          res
        })
      },
      fail(err) {
        console.log('scanCode fail: ', err)
      }
    })
  },
  onLoad() {
    this.setData({
      theme: wx.getSystemInfoSync().theme || 'light'
    })

    if (wx.onThemeChange) {
      wx.onThemeChange(({theme}) => {
        this.setData({theme})
      })
    }
  }
})
